#!/usr/bin/env python

#bootstraps a setuptools installation
from ez_setup import use_setuptools
use_setuptools()

from setuptools import setup, find_packages

info = {"__version__": None,
    "__author__": None,
    "__author_email__": None
}

f = open("pytoss/__init__.py", "r")
for line in f:
    for key in info.keys():
        if line.strip().startswith(key):
            info[key] = eval(line.split('=')[1])
f.close()

setup(
    name = "pytoss",
    version = info["__version__"],
    description = "pytoss is a powerful, no-hassle, pythonic deployment tool.",
# TODO: make a long_description
#     long_description="""
# """,
    author = info["__author__"],
    author_email = info["__author_email__"],
    url = "http://code.google.com/p/pytoss/",
    install_requires = ["paramiko>=1.7.3"],
    packages = find_packages(), #pull in all folders with __init__.py as packages
    scripts = ["scripts/toss", "scripts/pytossrc"],
    classifiers = [
        "Development Status :: 3 - Alpha",
        "Environment :: Console",
        "Intended Audience :: Developers",
        "Intended Audience :: System Administrators",
        "License :: OSI Approved :: MIT License",
        "Natural Language :: English",
        "Operating System :: OS Independent",
        "Programming Language :: Python",
        "Topic :: Software Development",
        "Topic :: System :: Distributed Computing",
        "Topic :: System :: Software Distribution",
        "Topic :: System :: Systems Administration",
    ],
)

try:
    import os
    
    f = open("scripts/profile")
    profile_completions = f.read()
    f.close()
    
    profile_file = open(os.path.join(os.environ["HOME"], ".profile"))
    profile = profile_file.read()
    profile_file.close()
    
    if profile.find(profile_completions) == -1:
        profile_writer = open(os.path.join(os.environ["HOME"], ".profile"), "a")
        profile_writer.write(profile_completions)
    
    print "Successfully installed command completion for toss."
except Exception, e:
    print e
    print "Error installing command completion for toss."
